﻿<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
	x:Class="MovieRental_Presentation.Templates.TemplatesResourceDictionary">
	
	<ControlTemplate x:Key="MenuButtonTemplate" TargetType="{x:Type Button}">
		<Border x:Name="border" BorderThickness="{StaticResource borderThickness}" BorderBrush="{DynamicResource borderBrush}" Padding="0" Width="{TemplateBinding Width}">
			<TextBlock x:Name="textBlock" Foreground="{StaticResource inputBoxBrush}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="{StaticResource menuButtonTextSize}" FontFamily="Lucida Sans" FontStyle="Italic">
				<ContentPresenter/>
			</TextBlock>
		</Border>
		<ControlTemplate.Triggers>
			<Trigger Property="IsMouseOver" Value="True">
				<Setter Property="Background" TargetName="border" Value="{StaticResource borderBrush}"/>
				<Setter Property="FontSize" TargetName="textBlock" Value="{StaticResource mouseOverButtonTextSize}"/>
				<Setter Property="FontStretch" TargetName="textBlock" Value="ExtraExpanded"/>
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>
	
	<Style x:Key="EditionItemStyle" TargetType="{x:Type ListBoxItem}">
		<Setter Property="Foreground" Value="White"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type ListBoxItem}">
					<Border x:Name="border" Style="{StaticResource ItemBorderStyle}">
						<Grid Margin="2">
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="*"/>
								<ColumnDefinition Width="Auto"/>
							</Grid.ColumnDefinitions>
							<Button x:Name="button" Grid.Column="1" Content="+" Width="30" Height="30" Margin="4" Click="addToCartButton_Click"/>
							<ContentPresenter Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
						</Grid>
					</Border>
					<ControlTemplate.Triggers>
						<Trigger Property="Selector.IsSelected" Value="False">
							<Setter Property="Visibility" TargetName="button" Value="Collapsed"/>
							<Setter Property="Background" TargetName="border" Value="{StaticResource itemBackgroundBrush}"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	
	<DataTemplate x:Key="EditionOnSaleTemplate">
		<Grid>
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="*"/>
				<ColumnDefinition Width="*"/>
				<ColumnDefinition Width="Auto"/>
			</Grid.ColumnDefinitions>
			<Grid.RowDefinitions>
				<RowDefinition/>
				<RowDefinition/>
			</Grid.RowDefinitions>
			<TextBlock Grid.Row="0" Grid.ColumnSpan="2" Text="{Binding MovieTitle}" TextWrapping="Wrap" Foreground="{StaticResource itemTitleBrush}"/>
			<Grid x:Name="discountGrid" Grid.Column="2" Grid.RowSpan="2" VerticalAlignment="Center">
				<Grid.Visibility>
					<Binding Path="IsSelected" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}" Converter="{StaticResource boolToVisibilityReverseConverter}"/>
				</Grid.Visibility>
				<Image Width="30" Height="30" Source="/MovieRental.Presentation;component/Images/discountLabel.png"/>
				<TextBlock Text="{Binding Path=DiscountValue, StringFormat=\{0\}%}" Panel.ZIndex="1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
			</Grid>
			
			<TextBlock Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Text="{Binding MediaTypeName}" HorizontalAlignment="Center" VerticalAlignment="Bottom"/>
			<TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding Entity.Publisher}" VerticalAlignment="Bottom" TextWrapping="Wrap" />
		</Grid>
	</DataTemplate>
	
	<Style x:Key="GeneralItemStyle" TargetType="{x:Type ListBoxItem}">
		<Setter Property="Foreground" Value="White"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type ListBoxItem}">
					<Border x:Name="border" Style="{StaticResource ItemBorderStyle}">
						<ContentPresenter VerticalAlignment="Center"/>
					</Border>
					<ControlTemplate.Triggers>
						<Trigger Property="Selector.IsSelected" Value="False">
							<Setter Property="Background" TargetName="border" Value="{StaticResource itemBackgroundBrush}"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	
	<Style x:Key="NoSelectionColorItemStyle" TargetType="{x:Type ListBoxItem}">
		<Setter Property="Foreground" Value="White"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type ListBoxItem}">
					<Border x:Name="border" Style="{StaticResource ItemBorderStyle}" Background="{StaticResource itemBackgroundBrush}">
						<ContentPresenter VerticalAlignment="Center"/>
					</Border>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	
	<Style x:Key="MarkerSelectionItemStyle" TargetType="{x:Type ListBoxItem}">
		<Setter Property="Foreground" Value="White"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type ListBoxItem}">
					<Grid>
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="Auto"/>
							<ColumnDefinition Width="*"/>
						</Grid.ColumnDefinitions>
						<Ellipse x:Name="marker" Grid.Column="0" Width="10" Height="10" Fill="Red" Margin="8"/>
						<ContentPresenter Margin="8" Grid.Column="1" VerticalAlignment="Center"/>
					</Grid>
					<ControlTemplate.Triggers>
						<Trigger Property="IsSelected" Value="False">
							<Setter Property="Visibility" TargetName="marker" Value="Hidden"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	
	
	<DataTemplate x:Key="CartDefaultTemplate">
		<Grid>
			<Grid.RowDefinitions>
				<RowDefinition/>
				<RowDefinition/>
			</Grid.RowDefinitions>
			
			<Grid Grid.Row="0">
				<Grid.RowDefinitions>
					<RowDefinition/>
					<RowDefinition/>
				</Grid.RowDefinitions>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="*"/>
					<ColumnDefinition Width="Auto"/>
					<ColumnDefinition Width="Auto"/>
				</Grid.ColumnDefinitions>
				<TextBlock Grid.Row="0" Grid.Column="0" Margin="8" Text="{Binding CustomerName}" Style="{DynamicResource ImportantTextStyle}"/>
				<TextBlock Grid.Row="1" Grid.Column="0" Margin="8" Text="{Binding Path=Entity.LoanDate, StringFormat=\{0:f\}}"/>
				<Image Margin="8" Height="60" Width="60" Grid.RowSpan="2" Grid.Column="2" Source="/MovieRental.Presentation;component/Images/discIcon.png" Stretch="Fill" VerticalAlignment="Center"/>
				<TextBlock Grid.RowSpan="2" Grid.Column="1" Margin="6" HorizontalAlignment="Center" Text="{Binding NotReturnedLoans}" VerticalAlignment="Center" FontSize="24" FontWeight="Bold" Foreground="#FFD9E500">
					<TextBlock.Effect>
						<DropShadowEffect/>
					</TextBlock.Effect>
				</TextBlock>
			</Grid>
			
			<Grid Grid.Row="1">
				<Grid.Visibility>
					<Binding Path="IsSelected" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}" Converter="{StaticResource booleanToVisibilityConverter}"/>
				</Grid.Visibility>
				
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="*"/>
					<ColumnDefinition Width="Auto"/>
				</Grid.ColumnDefinitions>
				
				<ListBox x:Name="listBox" Grid.Column="0" Margin="8,0" ItemsSource="{Binding Loans}" Style="{StaticResource GeneralListBoxStyle}" ItemContainerStyle="{DynamicResource MarkerSelectionItemStyle}" ItemTemplate="{DynamicResource LoanTemplate}" SelectionMode="Multiple"/>
				<StackPanel Grid.Column="2" Width="50" Margin="8">
					<Button x:Name="returnButton" Margin="0, 0, 0, 8" Click="returnButton_Click" 
							Visibility="{Binding SelectedIndex, Converter={StaticResource indexVisibilityConverter}, ElementName=listBox}"
							DataContext="{Binding SelectedItems, ElementName=listBox}"
							Style="{StaticResource IconButtonStyle}">
						<Image Source="/MovieRental.Presentation;component/Images/returnIcon.png" Width="50" Height="40"/>
					</Button>
					<Button x:Name="returnAllButton" Margin="0, 0, 0, 8" Click="returnAllButton_Click" DataContext="{Binding ItemsSource, ElementName=listBox}"
							Style="{StaticResource IconButtonStyle}">
						<Image Source="/MovieRental.Presentation;component/Images/returnAllIcon.png" Width="50" Height="40"/>
					</Button>
							
				</StackPanel>
				
			</Grid>
		</Grid>
	</DataTemplate>
	
	<DataTemplate x:Key="LoanTemplate">
		<Grid Margin="8">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="*"/>
				<ColumnDefinition Width="Auto"/>
				<ColumnDefinition Width="Auto"/>
			</Grid.ColumnDefinitions>
			<Grid.RowDefinitions>
				<RowDefinition/>
				<RowDefinition/>
			</Grid.RowDefinitions>
			<TextBlock Grid.Row="0" Grid.ColumnSpan="3" Text="{Binding MovieTitle}" TextWrapping="Wrap" FontSize="{StaticResource infoTextSize}" Foreground="{DynamicResource itemTitleBrush}"/>
			<TextBlock Grid.Row="1" Grid.ColumnSpan="3" Text="{Binding Publisher}" TextWrapping="Wrap"/>
			<TextBlock Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" Margin="8,0" Text="{Binding MediaTypeName}"/>
			<TextBlock Grid.Column="2" Grid.Row="1" VerticalAlignment="Center" Margin="8,0" Text="{Binding Path=Entity.PricePerDay, StringFormat=\{0:c\}}"/>
		</Grid>
	</DataTemplate>
	
</ResourceDictionary>